//1. 导入http模块
const htp = require('http');
//2. 创建服务器
const server = htp.createServer();
//3. 返回函数

server.on('request', function(req, res) {
    const url = req.url;
    let error = '404 Not found';

    if (url == '/' || url == '/index.html') {
        error = '<h1>首页</h1>'
    } else if (url == '/about.html') {
        error = '<h1>关于</h1>';
    }

    res.setHeader('Content-Type', 'text/html;charset=utf-8');

    res.end(error);
});

server.listen(80, () => {
    console.log('Server running at http://127.0.0.1');
})